package com.mingliu.transactionalevent.service;

import com.mingliu.transactionalevent.model.InsAsset;
import com.mingliu.transactionalevent.repository.InsAssetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Optional;

@Service
public class InsAssetService {

    @Resource
    InsAssetRepository insAssetRepository;

    @Resource
    private ApplicationEventPublisher publisher;

    @Transactional(rollbackFor = Exception.class)
    public void assetCount() {
        Optional<InsAsset> byId = insAssetRepository.findById(171L);
        if(byId.isPresent()){
            insAssetRepository.getById(171L);
        }
        publisher.publishEvent(byId.get());
    }
}
